/**
 * 
 */
package com.momosw.games.jericho.actions;

import com.momosw.games.engine.Action;
import com.momosw.games.engine.Game;
import com.momosw.games.engine.events.ActionEvent;
import com.momosw.games.engine.events.Event;
import com.momosw.games.engine.player.Player;
import com.momosw.games.engine.util.Utils;
import com.momosw.games.jericho.board.Card;
import com.momosw.games.jericho.board.TrumpetsCard;
import com.momosw.games.jericho.board.WallType;

/**
 * <b>Project:</b> JerichoCardGame<br />
 * <b>Package:</b> com.momosw.games.jericho.actions<br />
 * <b>Class:</b> PlayCardAction.java<br />
 * <br />
 * <i>GSI 2011</i><br />
 *
 * @author Miguel Coronado (miguelcb84@gmail.com)
 * @version	Aug 17, 2011
 *
 */
public class PlayCardAction implements Action, ActionEvent {

    private Game game;
    private Player current;
    private Card card;
    private WallType wall;
    
    /**
     * 
     * @param game
     * @param current
     */
    public PlayCardAction(Game game, Player current) {
        this.game = game;
        this.current = current;
    }

    /* (non-Javadoc)
     * @see com.momosw.games.engine.Action#execute(com.momosw.games.engine.Game, com.momosw.games.engine.Player)
     */
    public void execute() {
        card = (Card)current.chooseBetween(current.getHand());
        
        current.removeFromHand (card);
        
        if(card instanceof TrumpetsCard){
            wall = (WallType)current.chooseBetween(WallType.getTypes());
            Utils.notifyPlayers(game, current, this);
            
            game.getBoard().putInPlay(current, card, wall);
        }
        else {
            game.getBoard().putInPlay(current, card);
            
            Utils.notifyPlayers(game, current, this);
        }
        
    }

    /* (non-Javadoc)
     * @see com.momosw.games.engine.Action#getReadableName()
     */
    public String getReadableName() {
        return "Jugar una carta";
    }

    @Override
    public String toString() {
        return "PlayCardAction";
    }

    public Event hidePrivate() {
        return this;
    }

    public Action getAction() {
        return this;
    }

    public Card getCard() {
        return card;
    }

    public WallType getWallType() {
        return wall;
    }

    public Player getPlayer() {
        return current;
    }
    
}
